import 'package:flutter/material.dart';
import 'package:flutter_easyrefresh/easy_refresh.dart';
import 'package:flutter_framework_master/http/HttpConfig.dart';
import 'package:flutter_framework_master/http/HttpHelper.dart';
import 'package:flutter_framework_master/utils/PersistentStorage.dart';
import 'package:flutter_framework_master/widget/FreshListView.dart';
import 'package:flutter_framework_master/widget/SampleListItem.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:shared_preferences/shared_preferences.dart';

/**
 *Created by Jcy
 *on 2021/9/26
 */
class HomePage extends StatefulWidget {
  const HomePage({Key? key}) : super(key: key);

  @override
  _HomePageState createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
  List<String> mData = [];
  int count = 10;

  @override
  void initState() {
    // TODO: implement initState
    super.initState();

    initData();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        centerTitle: true,
        backgroundColor: Color(0xFFF4F4F4),
        automaticallyImplyLeading: false,
        brightness: Brightness.light,
        elevation: 0,
        // title: headWidget(),
      ),
      body: Container(
        child: FreshListView(
          itemBuilder: (index) {
            return listItem(index);
          },
          length: count,
          onRefresh: () async {
            await Future.delayed(Duration(seconds: 2), () {
              if (mounted) {
                setState(() {
                  count = 10;
                });
              }
            });
          },
          onLoad: () async {
            await Future.delayed(Duration(seconds: 2), () {
              if (mounted) {
                setState(() {
                  count = count + 10;
                });
              }
            });
          },
        ),
      ),
    );
  }

  listItem(int index) {
    return InkWell(
      child: SampleListItem(),
      onTap: () {
        print('object' + index.toString());
      },
    );
  }

  initData() async {
    PersistentStorage.instance.setStorage('jjj', 1111);
    int a = await PersistentStorage.instance.getStorage('jjj');
    print('object' + a.toString());
    var response = await HttpHelper.get(HttpConfig.urlPath['top']);
    print('object{$response}');
  }
}
